import subprocess
import requests
import re
import os
from urllib3.exceptions import InsecureRequestWarning
import datetime

# 禁用安全请求警告

Platform = "涩世小说"
today = datetime.date.today()  # 今天
yester = today - datetime.timedelta(days=1)
yesterday = str(yester).replace('-', '')


def seshi():
    try:
        requests.urllib3.disable_warnings(InsecureRequestWarning)
        r = requests.session()
        ff = r.get(url="http://auth-graphmovie.yymedias.com/Channel/Public/login", verify=False, timeout=15)
        html = ff.text.replace('\r', '').replace('\n', '').replace('\t', '')
        capt = re.findall('<img style="cursor:pointer;" src="(.*?)"', html)
        capturl = "http://auth-graphmovie.yymedias.com" + capt[0]
        cc = r.get(url=capturl, verify=False, timeout=15)
        with open("capt001.jpg", "wb") as f:
            f.write(cc.content)
            # 关闭文件流对象
            f.close()
        subprocess.call('capt001.jpg', shell=True)
        captcha = input("请输入验证码：")
        date = {
            "account": "",
            "password": "",
            "verify": str(captcha)
        }
        os.remove("capt001.jpg")
        rr = r.post(url="http://auth-graphmovie.yymedias.com/Channel/Public/login", data=date, verify=False, timeout=15)
        aa = r.get(url="http://auth-graphmovie.yymedias.com/Channel/Order/index", verify=False, timeout=15)
        html = aa.text.replace('\r', '').replace('\t', '').replace('\n', '')
        Amount_share = re.findall('昨日充值.*?¥<span>(\d+)</span>', html)[0]
        Amount_share = round(float(Amount_share) * 0.9, 2)
        date_time = yesterday
        return date_time, Amount_share, Platform
    except Exception:
        print("获取 涩世小说 数据失败")
        return '', 'None', Platform
    except ConnectionError:
        print("获取 涩世小说 数据 超时")
        return '', 'None', Platform